package com.hongdee.scm.enterwarehouse.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.scm.enterwarehouse.service.ITScmEnterWareHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 名  称:TScmEnterWarehouseController
 * 类  型:class
 * 描  述:
 * 路  径:com.hongdee.scm.enterwarehouse.controller
 * 作  者: 术洪超
 * 日  期:2017-05-15 13:48
 */
@RestController
@RequestMapping("/scm/enterWarehouse")
public class TScmEnterWarehouseController {

    @Autowired
    private ITScmEnterWareHouseService itScmEnterWareHouseService;

    /**
     * @param uid   登录用户 ID
     * @param token 登录用户 Token
     * @param id    主键 ID
     * @return ResultEntity
     * @throws Exception
     * @desc 打印入库单
     * @author 术洪超
     */

    @RequestMapping("/print")
    @ResponseBody
    public ResultEntity print(@RequestParam(name = "uid", defaultValue = "") String uid,
                              @RequestParam(name = "token", defaultValue = "") String token,
                              @RequestParam(name = "id", defaultValue = "") String id) throws Exception {
        ResultEntity res = new ResultEntity();
        itScmEnterWareHouseService.update(id, uid);
        res.setSuccess(true);
        res.setMsg("打印成功！");
        return res;
    }

    /**
     * 销售单分页查询
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/notEnterWareHouse")
    @ResponseBody
    public Map notEnterWareHouse(@RequestParam(name = "uid", defaultValue = "") String uid,
                                 @RequestParam(name = "token", defaultValue = "") String token,
                                 @RequestParam(name = "start", defaultValue = "0") String start,
                                 @RequestParam(name = "limit", defaultValue = "50") String limit,
                                 @RequestBody Map data) throws Exception {

        Map map = itScmEnterWareHouseService.notEnterWareHouse(data, start, limit, uid);
        map.put("success", true);
        map.put("msg", "查询成功!");
        return map;
    }


    /**
     * @param uid   登录用户 ID
     * @param token 登录用户 Token
     * @param vin    vin数组
     * @return ResultEntity
     * @throws Exception
     * @desc 打印入库单
     * @author 术洪超
     */

    @RequestMapping("/printValidate")
    @ResponseBody
    public ResultEntity printValidate(@RequestParam(name = "uid", defaultValue = "") String uid,
                                      @RequestParam(name = "token", defaultValue = "") String token,
                                      @RequestBody String[] vin) throws Exception {
        ResultEntity res = new ResultEntity();
        itScmEnterWareHouseService.updateValidateStatus(vin);
        res.setSuccess(true);
        res.setMsg("打印成功！");
        return res;
    }

    /**
     * 确认回库
     * @param uid
     * @param token
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/confirmBack")
    @ResponseBody
    public ResultEntity confirmBack(@RequestParam(name = "uid", defaultValue = "") String uid,
                                    @RequestParam(name = "token", defaultValue = "") String token,
                                    @RequestBody Map data) throws Exception {
        ResultEntity res = new ResultEntity();
        itScmEnterWareHouseService.confirmBack(data,uid);
        res.setSuccess(true);
        res.setMsg("确认回库成功！");
        return res;
    }
}
